package com.bwie.kafka.controller;

import com.bwie.common.domain.User;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Log4j2
@RestController
@RequestMapping("/kafka")
public class KafkaController {
    @Autowired
    private KafkaTemplate<Object,Object> kafkaTemplate;

    @GetMapping("/sendMsg")
    @Transactional
    public void testKafka(){
        User user = new User();
        user.setUserName("哈哈");
        kafkaTemplate.send("bwie",user);
    }
}
